package com.learn;

import java.util.Arrays;

/**
 * 冒泡排序
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arrs = new int[]{4, 2, 6, 1, 8, 9, 5};
        dubble(arrs);
        System.out.println(Arrays.toString(arrs));
    }

    public static void dubble(int[] arrs) {
        int length = arrs.length;
        if (arrs == null || length < 2) {
            return;
        }

        for (int i = length - 1; i >= 0; i--) {
            for (int j = 1; j <= i; j++) {
                if (arrs[j - 1] > arrs[j]) {
                    int swap = arrs[j - 1];
                    arrs[j - 1] = arrs[j];
                    arrs[j] = swap;
                }
            }
        }
    }
}
